package com.drugmanage.controller;

import com.drugmanage.Base.BaseController;
import com.drugmanage.entity.SaleDrug;
import com.drugmanage.model.ResultInfo;
import com.drugmanage.query.SaleDrugQuery;
import com.drugmanage.service.ISaleDrugService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.Map;

@Controller
@RequestMapping("user/saleDrug")
public class SaleDrugController extends BaseController {
    @Resource
    private ISaleDrugService saleDrugService;

    @RequestMapping("index/{state}")
    public String index(@PathVariable("state")Integer state){
        String index;
        switch (state){
            case 1:
                return "saledrug";
            case 2:
                return "buyDrug";
            default:
                return "404";
        }


    }

    @RequestMapping("saveSaleDrug")
    @ResponseBody
    public ResultInfo saveSaleDrug(SaleDrug saleDrug){
        saleDrugService.insert(saleDrug);
        return success("药品销售成功");
    }

    @RequestMapping("deleteSaleDrug")
    @ResponseBody
    public ResultInfo deleteSaleDrug(Integer[] ids){
        saleDrugService.deleteBatch(ids);
        return success("删除成功");
    }
    @RequestMapping("querySaleDrugByParams")
    @ResponseBody
    public Map<String,Object> querySaleDrugByParams(SaleDrugQuery saleDrugQuery){
        return saleDrugService.queryForPage(saleDrugQuery);
    }


}
